package com.wpw.dream.spider.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wpw.dream.spider.service.CatalogService;
import com.wpw.dream.spider.service.SpiderService;

@Controller
public class SpiderConfigController {

	@Autowired
	private CatalogService catalogService;
	
	@Autowired
	private SpiderService spiderService;
	
	@RequestMapping("/index1")
	public String index(String ids) {
		if (StringUtils.isNotBlank(ids)) {
			String[] split = ids.split(",");
			List<Long> spiderIds = new ArrayList<>();
			for (String string : split) {	
				spiderIds.add(Long.parseLong(string));
			}
			
			spiderService.doSpider(spiderIds);
		}
		
		return "index";
	}
	
}
